package org.tom.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.tom.basic.exception.MyException;
import org.tom.basic.util.JsonResult;
import org.tom.user.service.IVerifycodeService;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {
    @Autowired
    private IVerifycodeService verifycodeService;

    /*  接收对象可以用Map接收 */
    @PostMapping("/sendSmsCode")
    public JsonResult smsCode(@RequestBody Map<String, String> param){ // 接收短信，发送验证码
        try {
            verifycodeService.smsCode(param);
            return JsonResult.me();
        }catch (MyException e){
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("系统繁忙");
        }
    }
}
